home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio / Ray Dream Studio (CDRAYD1) (Ray Dream) (1995).iso / DREAMSDK.WIN / INCLUDE / 3DCOFAIL.H < prev    next >
C/C++ Source or Header  |  1995-11-04  |  4KB  |  117 lines

  1. /* $Id: 3DCOFAIL.h 1.2 1995/11/04 14:51:46 YannPC Exp $ */
  2. /*****************************************************************************\
  3. *                                                                             *
  4. * 3DCoFail.h                                                                                *
  5. *           Failure handling for COM extensions                               *
  6. *                                                                             *
  7. *           Copyright (c) 1995, Ray Dream, Inc. All rights reserved.          *
  8. *                                                                             *
  9. \*****************************************************************************/
  10.  
  11. #ifndef __3DCOFAIL__
  12. #define __3DCOFAIL__
  13.  
  14. struct IShUtilities;
  15.  
  16. /*****************************************************************************\
  17. *                                                                             *
  18. *   Shell Utilities pointer                                                   *
  19. *                                                                             *
  20. \*****************************************************************************/
  21. // gShellUtilities keeps a pointer on the Shell Utilities interface as given by
  22. // I3DExtension::ShellUtilitiesInit(). This is used as a convenient back-door
  23. // to the Shell. gShellUtilities is NULL by default, and is initialized by
  24. // InitCoFailure() (this is pretty much all what InitCoFailure() does). 
  25. extern IShUtilities* gShellUtilities;
  26.  
  27. /*****************************************************************************\
  28. *                                                                             *
  29. *   Failure Handling                                                          *
  30. *                                                                             *
  31. \*****************************************************************************/
  32. // Initialize gShellUtilities. Must be called to have working failure handling
  33. void InitCoFailure(IShUtilities* shellUtilities);
  34.  
  35. // Failure handling
  36. typedef int jmp_buf[16];
  37.  
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41.  
  42. void FailNIL(void* apointer);
  43. void FailOSErr(short err);
  44.  
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48.  
  49. #ifdef __cplusplus
  50.  
  51. #define VOLATILE(a) ((void)&a)
  52. #define DECLAREVOLATILE(a,b) a volatile b;
  53.  
  54. class FailInfo {
  55. public:
  56.     jmp_buf savedState;
  57.     short error;
  58.     long message;
  59.     FailInfo* nextInfo;
  60. public:
  61.     FailInfo();
  62.     inline void ReSignal();
  63.     inline void Success();
  64.     inline void Reset();
  65.     };
  66. typedef FailInfo* FailInfoPtr;
  67.  
  68. extern "C" {
  69. void __cdecl Failure(short error, long message);
  70. FailInfoPtr* __cdecl GetGTopHandler();
  71. typedef int (*RDsetjmpProc)(jmp_buf);
  72. extern RDsetjmpProc RDsetjmp;
  73. }
  74.  
  75.  
  76. //----------------------------------------------------------------------------------------
  77. // FailInfo inline method definitions
  78. //----------------------------------------------------------------------------------------
  79.  
  80. #define TRY(f)    \
  81.     f.nextInfo = *GetGTopHandler(),                    \
  82.     (f.nextInfo ? (*GetGTopHandler() = &f, ((*RDsetjmp)(f.savedState)==0)) : 1)
  83.  
  84. inline void FailInfo::Reset() {
  85.     error = 0;
  86.     message = 0;
  87.     nextInfo = 0;
  88.     }
  89.  
  90. inline FailInfo::FailInfo() {
  91.     }
  92.  
  93. inline void FailInfo::ReSignal() {
  94.     ::Failure(error, message);
  95.     }
  96.  
  97. inline void FailInfo::Success() {
  98.     *GetGTopHandler() = nextInfo;
  99.     }
  100.     
  101. #endif     /* __cplusplus */
  102.  
  103. /*****************************************************************************\
  104. *                                                                             *
  105. *   Memory management                                                         *
  106. *                                                                             *
  107. \*****************************************************************************/
  108.  
  109. void* RDmalloc(unsigned long  size);
  110. void* RDcalloc(unsigned long nmemb, unsigned long size);
  111. void* RDrealloc(void* ptr, unsigned long  size);
  112. void* RDcrealloc(void* ptr, unsigned long  size);
  113. void RDfree(void* ptr);
  114.  
  115. #endif
  116.  
  117.